package com.ladlee.validata.sms;

import com.ladlee.properties.SecurityProperties;
import com.ladlee.validata.ValidateCode;
import com.ladlee.validata.ValidateCodeGenerator;
import lombok.Data;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Auther: dingchang
 * @Date: 2018/12/22 09:43
 * @Description: 短信验证码生成器
 */
@Data
@Component(value = "smsValidateCodeGenerator")
public class SmsCodeGenerator implements ValidateCodeGenerator {

    @Autowired
    SecurityProperties securityProperties;

    @Override
    public ValidateCode generate() {
        String code = RandomStringUtils.randomNumeric(securityProperties.getCode().getSms().getLength());//生成随机验证码
        return new ValidateCode(code,securityProperties.getCode().getSms().getExpireIn());//构建验证码
    }
}
